﻿using NovoSerDes.A2B.MainForm;
using NovoSerDesEva;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NovoSerDes.Frame
{
    public partial class Frame : UIForm
    {
        private static Frame frame;
         private Frame()
        {
            InitializeComponent();

            // 禁用窗体的最大化按钮
            this.MaximizeBox = false;
        }

        private async void picbox_Ser_Des_Click(object sender, EventArgs e)
        {
            this.ShowProcessForm(200);
            try
            {
                MainForm mainForm = null;
                await Task.Run(() =>
                {
                    this.Invoke((MethodInvoker)delegate
                    {
                        mainForm = new MainForm();
                        mainForm.FormClosed += (s, args) => Show();
                        Hide();
                        this.HideProcessForm();
                        mainForm.Show();
                    });  
                }); 


            }
            catch(Exception ex)
            {
                MessageBox.Show($"发生错误:{ex.Message}");
            }
            
            //MainForm mainForm = new MainForm();
            //mainForm.FormClosed += (s, args) => Show();
            //this.HideProcessForm();
            //Hide();
            
        }

        private async void picbox_A_B_Click(object sender, EventArgs e)
        {
            //A2B_MainForm a2B_MainForm = new A2B_MainForm();
            //a2B_MainForm.FormClosed += (s, args) => Show();
            //Hide();
            //a2B_MainForm.Show();
            this.ShowProcessForm(200);
            try
            {
                A2B_MainForm mainForm = null;
                await Task.Run(() =>
                {
                    this.Invoke((MethodInvoker)delegate
                    {
                        mainForm = new A2B_MainForm();
                        mainForm.FormClosed += (s, args) => Show();
                        Hide();
                        this.HideProcessForm();
                        mainForm.Show();
                    });
                });

            }
            catch (Exception ex)
            {
                MessageBox.Show($"发生错误:{ex.Message}");
            }
        }

        public static Frame GetFrame()
        {
            if(frame == null)
            {
                frame = new Frame();
            }
            return frame;
        }

        private void picbox_Ser_Des_MouseEnter(object sender, EventArgs e)
        {
            this.picbox_Ser_Des.BorderStyle = BorderStyle.Fixed3D;
            this.picbox_Ser_Des.BackColor = Color.LightGray;
        }

        private void picbox_Ser_Des_MouseLeave(object sender, EventArgs e)
        {
            this.picbox_Ser_Des.BorderStyle = BorderStyle.None;
            this.picbox_Ser_Des.BackColor = Color.Transparent;
        }

        private void picbox_A_B_MouseEnter(object sender, EventArgs e)
        {
            this.picbox_A_B.BorderStyle = BorderStyle.Fixed3D;
            this.picbox_A_B.BackColor = Color.LightGray;
        }

        private void picbox_A_B_MouseLeave(object sender, EventArgs e)
        {
            this.picbox_A_B.BorderStyle = BorderStyle.None;
            this.picbox_A_B.BackColor = Color.Transparent;
        }
    }
}
